#ifndef OBJECT_VISITOR_H_
#define OBJECT_VISITOR_H_

#include <irrlicht/irrMap.h>
#include "SceneGraphVisitor.h"
#include "ObjectNode.h"

class ObjectVisitor : public SceneGraphVisitor
{
protected:
	// a draw list
	irr::core::map<int,ObjectNode*> drawList;

public:
	ObjectVisitor()
	{
	}
	
	virtual ~ObjectVisitor()
	{
	}
	
	inline irr::core::map<int, ObjectNode*> & 
		drawToList(SceneGraphNode * node)
	{
		// make sure the list is empty
		drawList.clear();
		
		// now visit all the nodes in the tree
		visitAll(node);
		
		// return the list
		return drawList;
	}

	virtual inline void visit(SceneGraphNode * node)
	{
		// update normally
		SceneGraphVisitor::visit(node);
		
		if (node->getType() & ObjectNode::TYPE)
		{
			// convert the node to a ObjectNode
			ObjectNode * dn = (ObjectNode*) node;
			
			// perform a pre render update
			dn->update();
		
			// then add to the draw lists
			if (dn->getVisible())
			{
				drawList.insert(dn->getDrawIndex(), dn);
			}
		}
	}
	
	
};

#endif
